﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using ZLCMS.Data.Model;
using ZLCMS.Business.Util;
using ZLCMS.Business.DwzFrame;

namespace ZLCMS.Web.SystemManage.Template.Web
{
    public partial class SelectTemplate : System.Web.UI.Page
    {
        protected int SelectedTemplateId = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {
                    repeater1.DataSource = session.CreateQuery("from CmsTemplateInfo order by Sort")
                        .List<CmsTemplateInfo>();


                    int utid = TemplateUtil.GetUserTemplateId(UserKit.GetUserAccountWithoutException());
                    CmsUserTemplateInfo utemp = session.Get<CmsUserTemplateInfo>(utid);
                    SelectedTemplateId = (int)utemp.TempId;
                }
                repeater1.DataBind();
            }
            else
            {
                TemplateUtil.CreateUserTemplate(UserKit.GetUserAccountWithoutException(), Int32.Parse(Request["selectedid"]));
                new FrameHelper(this).Alert(new ReturnCode()
                {
                    statusCode = 200,
                    callbackType = "closeCurrent",
                    message = "操作成功",
                    navTabId = "163"
                });
            }
        }
    }
}